package com.ruoyi.local.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.local.domain.TcTest;
import com.ruoyi.local.service.ITcTestService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代码生成测试Controller
 * 
 * @author ruoyi
 * @date 2020-11-22
 */
@Controller
@RequestMapping("/local/test")
public class TcTestController extends BaseController
{
    private String prefix = "local/test";

    @Autowired
    private ITcTestService tcTestService;

    @RequiresPermissions("local:test:view")
    @GetMapping()
    public String test()
    {
        return prefix + "/test";
    }

    /**
     * 查询代码生成测试列表
     */
    @RequiresPermissions("local:test:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TcTest tcTest)
    {
        startPage();
        List<TcTest> list = tcTestService.selectTcTestList(tcTest);
        return getDataTable(list);
    }

    /**
     * 导出代码生成测试列表
     */
    @RequiresPermissions("local:test:export")
    @Log(title = "代码生成测试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TcTest tcTest)
    {
        List<TcTest> list = tcTestService.selectTcTestList(tcTest);
        ExcelUtil<TcTest> util = new ExcelUtil<TcTest>(TcTest.class);
        return util.exportExcel(list, "test");
    }

    /**
     * 新增代码生成测试
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代码生成测试
     */
    @RequiresPermissions("local:test:add")
    @Log(title = "代码生成测试", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TcTest tcTest)
    {
        return toAjax(tcTestService.insertTcTest(tcTest));
    }

    /**
     * 修改代码生成测试
     */
    @GetMapping("/edit/{tcId}")
    public String edit(@PathVariable("tcId") Integer tcId, ModelMap mmap)
    {
        TcTest tcTest = tcTestService.selectTcTestById(tcId);
        mmap.put("tcTest", tcTest);
        return prefix + "/edit";
    }

    /**
     * 修改保存代码生成测试
     */
    @RequiresPermissions("local:test:edit")
    @Log(title = "代码生成测试", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TcTest tcTest)
    {
        return toAjax(tcTestService.updateTcTest(tcTest));
    }

    /**
     * 删除代码生成测试
     */
    @RequiresPermissions("local:test:remove")
    @Log(title = "代码生成测试", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tcTestService.deleteTcTestByIds(ids));
    }
}
